package com.econ.powercloud.ems.service.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.econ.powercloud.ems.dal.entity.EmsEnergyStation;
import com.econ.powercloud.ems.dal.mapper.EmsEnergyStationMapper;
import com.mysql.cj.util.StringUtils;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Author : zjf
 * @Description : 储能站DAO层
 * @Date : 2021/7/28 17:23
 * @Modified by : zjf
 */
@Repository
public class EmsEnergyStationDAO extends ServiceImpl<EmsEnergyStationMapper, EmsEnergyStation> {

    /**
     * 模糊搜索储能站
     * @param searchName
     * @param pageNo
     * @param pageSize
     * @return
     */
    public Page<EmsEnergyStation> selectListByCondition(List<String> companyIds, String searchName, Integer pageNo, Integer pageSize) {
        LambdaQueryWrapper<EmsEnergyStation> emsEnergyStationLambdaQueryWrapper = Wrappers.lambdaQuery();
        emsEnergyStationLambdaQueryWrapper.in(!CollectionUtils.isEmpty(companyIds), EmsEnergyStation::getCompanyId, companyIds);
        emsEnergyStationLambdaQueryWrapper.like(!StringUtils.isNullOrEmpty(searchName), EmsEnergyStation::getEnergyStationName, searchName);
        emsEnergyStationLambdaQueryWrapper.orderByAsc(EmsEnergyStation::getGmtCreate);
        Page<EmsEnergyStation> emsEnergyStationPage = new Page<>(pageNo, pageSize);
        return this.baseMapper.selectPage(emsEnergyStationPage, emsEnergyStationLambdaQueryWrapper);
    }

    public Page<EmsEnergyStation> selectListByIdList(List<String> idList, Integer pageNo, Integer pageSize) {
        LambdaQueryWrapper<EmsEnergyStation> wrapper = Wrappers.<EmsEnergyStation>lambdaQuery()
                .in(EmsEnergyStation::getEnergyStationId, idList);
        Page<EmsEnergyStation> page = new Page<>(pageNo, pageSize);
        return this.baseMapper.selectPage(page, wrapper);
    }

    /**
     * 查询全部储能站
     */
    public List<EmsEnergyStation> selectAll(){
        LambdaQueryWrapper<EmsEnergyStation> emsEnergyStationLambdaQueryWrapper = Wrappers.lambdaQuery();
        return this.baseMapper.selectList(emsEnergyStationLambdaQueryWrapper);
    }

    /**
     *按储能站id查询
     */
    public EmsEnergyStation selectOneByStationId(String stationId){
        LambdaQueryWrapper<EmsEnergyStation> emsEnergyStationLambdaQueryWrapper = Wrappers.lambdaQuery();
        emsEnergyStationLambdaQueryWrapper.eq(!StringUtils.isNullOrEmpty(stationId), EmsEnergyStation::getEnergyStationId, stationId);
        return this.baseMapper.selectOne(emsEnergyStationLambdaQueryWrapper);
    }

    public List<EmsEnergyStation> selectListByConpanyList(List<String> companyIds) {
        LambdaQueryWrapper<EmsEnergyStation> wrapper = Wrappers.lambdaQuery();
        wrapper.in(CollectionUtils.isNotEmpty(companyIds),EmsEnergyStation::getCompanyId,companyIds);
        return this.baseMapper.selectList(wrapper);
    }
}
